<?php
/**
 * 会员邀请
 * @return
 * @author yuncran@126.com
 */

namespace app\model;

use app\BaseModel;
use app\CacheKey;

class UserInviteModel extends BaseModel
{

    protected $pk = "id";

    protected $name = "user_invite";

    protected $append = ['user'];

    public function getUserAttr($value, $data)
    {
        return UserModel::where(['id' => $data['to_user_id']])->field('id,nickname,avatar,email,level,verification')->append(['level_name'])
            ->withAttr('level_name', function ($value, $data) {
                return UserLevelModel::where(['id' => $data['level']])->cache(CacheKey::level_title)->value('title');
            })->find();
    }



}